<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
<meta name="viewport"
      content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

    <meta name="author" content="kissdata">


    <meta name="subtitle" content="人生笔记">


    <meta name="description" content="南邮计算机学院2021毕业生王鹏的介绍，cs软件工程专业">


    <meta name="keywords" content="wangpeng 王鹏 南邮 南京">


<title>开发环境 | CentOS 安装各种数据库 | 王鹏的小岛</title>



    <link rel="icon" href="/myIcon.ico">




    <!-- stylesheets list from _config.yml -->
    
    <link rel="stylesheet" href="/css/style.css">
    



    <!-- scripts list from _config.yml -->
    
    <script src="/js/script.js"></script>
    
    <script src="/js/tocbot.min.js"></script>
    



    
    
        <!-- MathJax配置，可通过单美元符号书写行内公式等 -->
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
    "HTML-CSS": {
        preferredFont: "TeX",
        availableFonts: ["STIX","TeX"],
        linebreaks: { automatic:true },
        EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50)
    },
    tex2jax: {
        inlineMath: [ ["$", "$"], ["\\(","\\)"] ],
        processEscapes: true,
        ignoreClass: "tex2jax_ignore|dno",
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    },
    TeX: {
        equationNumbers: { autoNumber: "AMS" },
        noUndefined: { attributes: { mathcolor: "red", mathbackground: "#FFEEEE", mathsize: "90%" } },
        Macros: { href: "{}" }
    },
    messageStyle: "none"
    });
</script>
<!-- 给MathJax元素添加has-jax class -->
<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>
<!-- 通过连接CDN加载MathJax的js代码 -->
<script type="text/javascript" async
        src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-MML-AM_CHTML">
</script>


    


<meta name="generator" content="Hexo 7.0.0"></head>

<body>
    <script>
        // this function is used to check current theme before page loaded.
        (() => {
            const currentTheme = window.localStorage && window.localStorage.getItem('theme') || '';
            const isDark = currentTheme === 'dark';
            const pagebody = document.getElementsByTagName('body')[0]
            if (isDark) {
                pagebody.classList.add('dark-theme');
                // mobile
                document.getElementById("mobile-toggle-theme").innerText = "· Dark"
            } else {
                pagebody.classList.remove('dark-theme');
                // mobile
                document.getElementById("mobile-toggle-theme").innerText = "· Light"
            }
        })();
    </script>

    <div class="wrapper">
        <header>
    <nav class="navbar">
        <div class="container">
            <div class="navbar-header header-logo"><a href="/">侠之大者</a></div>
            <div class="menu navbar-right">
                
                    <a class="menu-item" href="/update/mystate">Career</a>
                
                    <a class="menu-item" href="/category">Legend</a>
                
                    <a class="menu-item" href="/about">Me</a>
                
                <input id="switch_default" type="checkbox" class="switch_default">
                <label for="switch_default" class="toggleBtn"></label>
            </div>
        </div>
    </nav>

    
    <nav class="navbar-mobile" id="nav-mobile">
        <div class="container">
            <div class="navbar-header">
                <div>
                    <a href="/">侠之大者</a><a id="mobile-toggle-theme">·&nbsp;Light</a>
                </div>
                <div class="menu-toggle" onclick="mobileBtn()">&#9776; Menu</div>
            </div>
            <div class="menu" id="mobile-menu">
                
                    <a class="menu-item" href="/update/mystate">Career</a>
                
                    <a class="menu-item" href="/category">Legend</a>
                
                    <a class="menu-item" href="/about">Me</a>
                
            </div>
        </div>
    </nav>

</header>
<script>
    var mobileBtn = function f() {
        var toggleMenu = document.getElementsByClassName("menu-toggle")[0];
        var mobileMenu = document.getElementById("mobile-menu");
        if(toggleMenu.classList.contains("active")){
           toggleMenu.classList.remove("active")
            mobileMenu.classList.remove("active")
        }else{
            toggleMenu.classList.add("active")
            mobileMenu.classList.add("active")
        }
    }
</script>
            <div class="main">
                <div class="container">
    
    
        <div class="post-toc">
    <div class="tocbot-list">
    </div>
    <div class="tocbot-list-menu">
        <a class="tocbot-toc-expand" onclick="expand_toc()">Expand all</a>
        <a onclick="go_top()">Back to top</a>
        <a onclick="go_bottom()">Go to bottom</a>
    </div>
</div>

<script>
    var tocbot_timer;
    var DEPTH_MAX = 6; // 为 6 时展开所有
    var tocbot_default_config = {
        tocSelector: '.tocbot-list',
        contentSelector: '.post-content',
        headingSelector: 'h1, h2, h3, h4, h5',
        orderedList: false,
        scrollSmooth: true,
        onClick: extend_click,
    };

    function extend_click() {
        clearTimeout(tocbot_timer);
        tocbot_timer = setTimeout(function() {
            tocbot.refresh(obj_merge(tocbot_default_config, {
                hasInnerContainers: true
            }));
        }, 420); // 这个值是由 tocbot 源码里定义的 scrollSmoothDuration 得来的
    }

    document.ready(function() {
        tocbot.init(obj_merge(tocbot_default_config, {
            collapseDepth: 1
        }));
    });

    function expand_toc() {
        var b = document.querySelector('.tocbot-toc-expand');
        var expanded = b.getAttribute('data-expanded');
        expanded ? b.removeAttribute('data-expanded') : b.setAttribute('data-expanded', true);
        tocbot.refresh(obj_merge(tocbot_default_config, {
            collapseDepth: expanded ? 1 : DEPTH_MAX
        }));
        b.innerText = expanded ? 'Expand all' : 'Collapse all';
    }

    function go_top() {
        window.scrollTo(0, 0);
    }

    function go_bottom() {
        window.scrollTo(0, document.body.scrollHeight);
    }

    function obj_merge(target, source) {
        for (var item in source) {
            if (source.hasOwnProperty(item)) {
                target[item] = source[item];
            }
        }
        return target;
    }
</script>
    

    
    <article class="post-wrap">
        <header class="post-header">
            <h1 class="post-title">开发环境 | CentOS 安装各种数据库</h1>
            
                <div class="post-meta">
                    
                        Author: <a itemprop="author" rel="author" href="/">kissdata</a>
                    

                    
                        <span class="post-time">
                        Date: <a href="#">Oct 3, 2022&nbsp;&nbsp;0:00</a>
                        </span>
                    
                    
                        <span class="post-category">
                    Category:
                            
                                <a href="/categories/Review/">Review</a>
                            
                        </span>
                    
                </div>
            
        </header>

        <div class="post-content">
            <p>have a look at the <strong>section 4</strong> introducing how to use <code>pg14</code> in Ubuntu.</p>
<h2 id="一、Centos7-安装-MySQL8"><a href="#一、Centos7-安装-MySQL8" class="headerlink" title="一、Centos7 安装 MySQL8"></a>一、Centos7 安装 MySQL8</h2><h3 id="1-1-卸载影响依赖"><a href="#1-1-卸载影响依赖" class="headerlink" title="1.1 卸载影响依赖"></a>1.1 卸载影响依赖</h3><p>第一次安装基本都失败，需要在安装前先卸载多余的依赖。主要是针对已经默认安装 mariadb 的情况。</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 如果提示 “服务器已经安装了Mariadb!!” </span></span><br><span class="line">rpm -qa|grep mariadb </span><br><span class="line">rpm -e --nodeps ... <span class="comment"># 卸载前面命令显示的组件</span></span><br></pre></td></tr></table></figure>

<h3 id="1-2-安装公司-mysql包"><a href="#1-2-安装公司-mysql包" class="headerlink" title="1.2 安装公司 mysql包"></a>1.2 安装公司 mysql包</h3><p>MySQL 官网的原始包限制“安装后必须修改密码才能做其他事。”，安装时还需要安装mysql驱动，公司的都包已经调好，配置好了，并且端口也改了。</p>
<p>安装时会自动装需要的东西，并且修改密码。安装后服务已启动。</p>
<p><img src="/image/review_centos7/mysql_set2.png"></p>
<p>安装过程略。</p>
<blockquote>
<p>如果从官网安装，参考 <a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/367327903">安装 MySQL 8 ( zhihu.com )</a> 安装时要自己下载驱动，安装完后，要自己 <code>systemctl start mysqld</code> 启动，并且自己修改root密码，不然xshell不能远程连接。不要按着 csdn 随大流安装，可能出现 <code>Unit mysql.service could not be found</code> 的错误。</p>
</blockquote>
<h3 id="1-3-创建项目用户的SQL语句"><a href="#1-3-创建项目用户的SQL语句" class="headerlink" title="1.3 创建项目用户的SQL语句"></a>1.3 创建项目用户的SQL语句</h3><p>一个项目一个特定mysql用户来控制管理相关的数据库。</p>
<p>【创建使用MySQL的 root用户】（一般不用）</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">CREATE user &#x27;root&#x27;@&#x27;%&#x27; IDENTIFIED BY &#x27;root&#x27;;</span><br><span class="line">grant all privileges on *.* to &#x27;root&#x27;@&#x27;%&#x27;;</span><br><span class="line">flush privileges;</span><br></pre></td></tr></table></figure>

<p>其中 %表示匹配所有主机。</p>
<p>【创建使用MySQL的普通用户】</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">create database friendsdb default character set utf8 collate utf8_general_ci;</span><br><span class="line">create user &#x27;wangpeng&#x27;@&#x27;%&#x27; identified by &#x27;like2022&#x27;;</span><br><span class="line">grant all on friendsdb.* to &#x27;wangpeng&#x27;;</span><br><span class="line">flush privileges;</span><br></pre></td></tr></table></figure>

<h3 id="1-4-Navicat连接"><a href="#1-4-Navicat连接" class="headerlink" title="1.4 Navicat连接"></a>1.4 Navicat连接</h3><p>防火墙问题</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">firewall-cmd --permanent --zone=public --add-port=3306/tcp</span><br></pre></td></tr></table></figure>

<h2 id="二、Centos7-安装-PG14"><a href="#二、Centos7-安装-PG14" class="headerlink" title="二、Centos7 安装 PG14"></a>二、Centos7 安装 PG14</h2><p>PG最新版16，yum 安装默认只有 <code>v9</code> 。略</p>
<h2 id="三、Centos7-安装-mongo5"><a href="#三、Centos7-安装-mongo5" class="headerlink" title="三、Centos7 安装 mongo5"></a>三、Centos7 安装 mongo5</h2><p>Download <a target="_blank" rel="noopener" href="https://www.mongodb.com/try/download/community">MongoDB Community</a></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-6.0.15.tgz</span><br></pre></td></tr></table></figure>

<p>安装v5，80M左右，直接wget下载很快，开箱即用</p>
<h3 id="3-1-创建数据目录"><a href="#3-1-创建数据目录" class="headerlink" title="3.1 创建数据目录"></a>3.1 创建数据目录</h3><p>默认目录 <code>/data/db</code></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">sudo mkdir -p /data/db</span><br><span class="line">sudo mkdir -p /data/logs</span><br><span class="line">sudo touch /data/logs/mongodb.log</span><br><span class="line">chmod -R 777 /data</span><br><span class="line">chmod -R 777 /data/db</span><br><span class="line">chmod -R 777 /data/logs</span><br></pre></td></tr></table></figure>

<h3 id="3-2-部署安装包"><a href="#3-2-部署安装包" class="headerlink" title="3.2 部署安装包"></a>3.2 部署安装包</h3><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">下载 5.0</span></span><br><span class="line">wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.12.tgz</span><br><span class="line">tar xvf mongodb-linux-* -C /usr/local</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">换名</span></span><br><span class="line">mv /usr/local/mongodb-linux-* /usr/local/mongodb</span><br><span class="line">chmod -R 777 /usr/local/mongodb</span><br></pre></td></tr></table></figure>

<p>配置环境变量</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">vim /etc/profile</span><br><span class="line">export PATH=$PATH:/usr/local/mongodb/bin # 和解压目录一致</span><br><span class="line">export PATH</span><br><span class="line">. /etc/profile</span><br><span class="line"></span><br><span class="line">mongod # 开启测试，不带配置直接开启(不推荐)</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h3 id="3-3-配置数据库"><a href="#3-3-配置数据库" class="headerlink" title="3.3 配置数据库"></a>3.3 配置数据库</h3><p>目的：可以直接使用，无需账号密码，日志输出到固定目录。</p>
<p>方法：新建 <code>/usr/local/mongodb/mongodb.conf</code>文件，输入以下内容</p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">dbpath=/data/db</span><br><span class="line">logpath=/data/logs/mongodb.log</span><br><span class="line">port=<span class="number">27017</span></span><br><span class="line">fork=<span class="literal"><span class="keyword">true</span></span></span><br><span class="line">auth=<span class="literal"><span class="keyword">false</span></span></span><br><span class="line">bind_ip=<span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span></span><br><span class="line">logappend=<span class="literal"><span class="keyword">true</span></span></span><br></pre></td></tr></table></figure>

<h3 id="3-4-使用"><a href="#3-4-使用" class="headerlink" title="3.4 使用"></a>3.4 使用</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">mongod --config /usr/local/mongodb/mongodb.conf</span><br><span class="line">mongod --shutdown --config /usr/local/mongodb/mongodb.conf</span><br><span class="line"></span><br><span class="line">mongod --fork --logpath 0706.<span class="built_in">log</span> --httpinterface --rest <span class="comment"># 打开28017网页接口</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 检查启停状态</span></span><br><span class="line">ps -ef | grep mongodb  <span class="comment"># 如果只显示一行表示服务未启动</span></span><br></pre></td></tr></table></figure>





<h2 id="附-激活Navicat16"><a href="#附-激活Navicat16" class="headerlink" title="附  激活Navicat16"></a>附  激活Navicat16</h2><p>【安装】打开官网:  <a target="_blank" rel="noopener" href="https://navicat.com.cn/download/navicat-premium">https://navicat.com.cn/download/navicat-premium</a></p>
<p>选择你需要的版本下载，常用的是 Windows-Navicat Premium 16, 选择3个里面任意一个路线。</p>
<p>安装过程就是一路下一步。</p>
<p>【激活】</p>
<p>方法1，下载 <code>https://txx.lanzoub.com/iclta01fbi4f</code>， 双击 Bat文件。</p>
<p>方法2，学生申请 <a target="_blank" rel="noopener" href="https://www.navicat.com.cn/sponsorship/education/student">https://www.navicat.com.cn/sponsorship/education/student</a></p>

        </div>

        
            <section class="post-copyright">
                
                
                
                
                     <p class="copyright-item">
                         <span>Slogan:</span>
                         <span>人生三大错觉：我躲得过去，我能反杀，是不是<strong>喜欢我?</strong></span>
                     </p>
                

            </section>
        
        <section class="post-tags">
            <div>
            </div>
            <div>
                <a href="javascript:window.history.back();">back</a>
                <span>· </span>
                <a href="/">home</a>
            </div>
        </section>
        <section class="post-nav">
            
                <a class="prev" rel="prev" href="/2022/10-24/review_rabbitmq/">项目经验 | 连接 RabbitMQ</a>
            
            
            <a class="next" rel="next" href="/2022/09-19/deploy_shida/">💥 | Centos7 搭建短视频平台</a>
            
        </section>


    </article>
</div>

            </div>
            <footer id="footer" class="footer">
    <div class="copyright">
        <span>187-9597-5517 &nbsp; 王鹏 @ <a href="https://cs.njupt.edu.cn/" target="_blank">njupt</a</span>
    </div>
</footer>

    </div>
</body>

</html>